<%@ page contentType="text/html;charset=UTF-8"%>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
<title>退换货记录</title>
<meta name="decorator" content="default" />
<script type="text/javascript">
	function page(n, s) {
		$("#pageNo").val(n);
		$("#pageSize").val(s);
		$("#searchForm").submit();
		return false;
	}
	
	function showDetail(returnCode){
		$.ajax({
			url : "${ctx}/sys/ordersexchangehistory/form",
			data : {
				"returnCode" : returnCode
			},
			//async:false,
			dataType : "json",
			type : "post",
			success : function(data) {
				if(data.resultCode == "0"){
					alert(data.resultMessage);
					return;
				}
				var total = 0;
				$("#viewCode").html(data.returnsGoods.returnCode);
				$("#detailTable").empty();
				$("#detailTable").append("<tr><td>商品名称</td><td>单价</td><td>购买数量</td><td>退换货数量</td><td>退换货金额</td></tr>");
				for(var i=0;i<data.detailCount.length;i++){
					total += parseInt(data.detailCount[i].returnGoodsDetailMoney);
					$("#detailTable").append(createRow(i,data.detailCount[i]));
				}
				$("#detailTable").append("<tr><td colspan='5'>退换货总额:"+total+"</td></tr>");
				$("#remarks").html(data.returnsGoods.reason);
				$("#importBox_goods").show();
			},
			error : function() {
				alert("网络异常");
			}
		})
	}
	
	function createRow(index,data){
		return "<tr>"+
					"<td>"+data.goodsCnName+"</td><td>"+data.price+"</td><td>"+data.num+"</td><td>"+data.returnGoodsDetailNum+"</td><td>"+data.returnGoodsDetailMoney+"</td>"+
			   "</tr>";
	}
	
	function close_imbox() {
		$("#importBox_goods").hide();
	}
</script>

<style>
#importBox_goods {
	position: fixed;
	padding: 0 15px;
	width: 350px;
	background: #FFF;
	top: 10%;
	left: 25%;
	margin: 0 auto;
	border: 1px solid #CCC;
	box-shadow: 3px 3px 10px 4px #DDD;
	z-index: 9999;
}

#importBox_goods .ib_bottom {
	margin-bottom: 35px;
}
</style>
</head>
<body>
	<ul class="nav nav-tabs">
		<li class="active"><a href="${ctx}/sys/ordersexchangehistory/">退换货记录列表</a></li>
	</ul>
	<form:form id="searchForm" modelAttribute="returnsGoods"
		action="${ctx}/sys/ordersexchangehistory/" method="post"
		class="breadcrumb form-search">
		<input id="pageNo" name="pageNo" type="hidden" value="${page.pageNo}" />
		<input id="pageSize" name="pageSize" type="hidden"
			value="${page.pageSize}" />
		<ul class="ul-form">
			<li><label>退换货单号：</label> <form:input path="returnCode"
					htmlEscape="false" maxlength="50" class="input-medium" /></li>

			<li><label>订单编号：</label> <form:input path="orderCode"
					htmlEscape="false" maxlength="50" class="input-medium" /></li>

			<li><label>退换货时间：</label> <input name="startTime" type="text"
				readonly="readonly" placeholder="开始时间" class="input-medium Wdate "
				value="<fmt:formatDate value="${returnsGoods.createDate }" pattern="yyyy-MM-dd HH:mm:ss"/>"
				onclick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss',isShowClear:false});" />
				&nbsp;&nbsp;&nbsp;&nbsp; <input name="endTime" type="text"
				readonly="readonly" placeholder="结束时间" class="input-medium Wdate "
				value="<fmt:formatDate  value="${returnsGoods.createDate }" pattern="yyyy-MM-dd HH:mm:ss"/>"
				onclick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss',isShowClear:false});" />
			</li>
			<li>
			<li><label>下单门店类型：</label> <form:select id="storeType"
					path="storeType" class="input-medium">
					<form:option value="" label="所有" />
					<form:options items="${fns:getDictList('store_type')}"
						htmlEscape="false" itemValue="value" itemLabel="label" />
				</form:select></li>
			<li><label>下单门店：</label> <form:select id="buyStoreCode"
					path="buyStoreCode" class="input-medium">
					<form:option value="" label="所有" />
					<form:options items="${store}" htmlEscape="false" itemValue="code"
						itemLabel="cnName" />
				</form:select></li>
			<li class="btns"><input id="btnSubmit" class="btn btn-primary"
				type="submit" value="查询" /></li>
			<li class="clearfix"></li>
		</ul>
	</form:form>
	<sys:message content="${message}" />
	<table id="contentTable"
		class="table table-striped table-bordered table-condensed">
		<thead>
			<tr>
				<th>序号</th>
				<th>退换货单号</th>
				<th>订单编号</th>
				<th>下单用户</th>
				<th>退换货数量</th>
				<th>退换货金额</th>
				<th>下单门店</th>
				<th>退换货时间</th>
			</tr>
		</thead>
		<tbody>
			<c:forEach items="${page.list}" var="bean" varStatus="status">
				<tr>
					<td>${status.index+1}</td>
					<td><a href="javascript:void(0);" onclick="showDetail('${bean.returnCode}')">${bean.returnCode}</a></td>
					<td><a href="${ctx}/sys/orders/form?id=${bean.ordersId}">${bean.orderCode}</a></td>
					<td><c:choose>
							<c:when test="${bean.userType == 1}">
							${bean.userName}
						</c:when>
							<c:when test="${bean.userType == 2}">
							${bean.userCompany}
						</c:when>
						</c:choose></td>
					<td>${bean.returnGoodsDetailNum}</td>
					<td>${bean.returnGoodsDetailMoney}</td>
					<td>${bean.storeCnName}</td>
					<td><fmt:formatDate value="${bean.createDate}"
							pattern="yyyy-MM-dd HH:mm:ss" /></td>
				</tr>
			</c:forEach>
		</tbody>
	</table>
	<div class="pagination">${page}</div>

	<!-- 弹框 -->
	<div id="importBox_goods" class="hide">
			<input type="hidden" id="ordersCode" name="orderCode" value="" />
			<input type="hidden" id="userId" name="userId" value="" />
			<div style="margin-top: 20px;">
				退换货单号:<span id="viewCode"></span>
				<br>
				<table id="detailTable" class="table table-striped table-bordered table-condensed">
					
				</table>
				退换货说明:
				<span id="remarks"></span>
			</div>
		<div class='ib_bottom'>
			<input id="btnCancel" class="btn"
				type="button" style='margin-left: 10px;' value="关闭"
				onclick="close_imbox()" />
		</div>
	</div>
</body>
</html>